package com.deng.springboot.demo.web.controller;

import com.deng.springboot.demo.web.model.dto.UserDto;
import com.deng.springboot.demo.web.model.vo.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.text.MessageFormat;
import java.time.LocalDate;

import static com.deng.springboot.demo.common.util.JsonUtils.*;

/**
 * @author 邓力宾
 * @date 2020/3/1016:21
 * @Description:
 */
@RestController// 包括 了@Controller @ResponseBody
@RequestMapping("/hello")
@Api(tags = {"测试接口"})
public class HelloController extends BaseController {

    /**
     * 请求测试
     * @return
     */
    @ApiOperation(value = "测试请求接口", nickname = "昵称", notes = "notes")
    @GetMapping(value = "/helloWorld")
    public ResponseResult<Object> helloWorld(){
        //int i = 1 /0; //异常测试
        return new ResponseResult<>(200, "hello world!", LocalDate.now());
    }

    /**
     *提交数据测试
     * @return
     */
    @PostMapping(value = "/postData")
    @ApiOperation(value = "测试提交数据接口", nickname = "昵称", notes = "notes")
    public ResponseResult<Object> postData(@RequestBody UserDto userDto){
        String s = toJsonString(userDto);
        logger.info(MessageFormat.format("提交结果{0}", s));
        return new ResponseResult<>(200, "success", userDto);
    }


}
